package com.grsu.phonestation.web;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.grsu.phonestation.domain.Service;
import com.grsu.phonestation.domain.User;
import com.grsu.phonestation.service.ServiceService;

@Controller
@RequestMapping("/home")
public class HomeController {

	@Autowired
	@Qualifier("serviceServiceImpl")
	private ServiceService<Service> serviceService;
	
	
	@RequestMapping(method = { RequestMethod.GET })
	public ModelAndView home(HttpSession session, Model model) {

		ModelAndView mav = new ModelAndView();
		
		Object userObject = session.getAttribute("user");
		if ((userObject != null) && (userObject instanceof User)) {
			User user = (User) userObject;
			mav.addObject("user", user);
			mav.setViewName("home");
		}else{
			mav.setViewName("login");
		}

		return mav;
	}
}
